<?php
class Category extends MultiLevel {
    protected $_name;
    protected $_primary = "category_id";
    protected $_prefix_field = "";

    function __construct() {
        $this->_name = DB_PREFIX . "category";
        parent::__construct();
    }

    public function getColumns() {
        //$results = array('category_id', 'admin_title', 'parent', 'left', 'right', 'status');
        $results = array('category_id', 'admin_title', 'parent', 'left', 'right', 'demo', 'status', 'main_image', 'languageID', 'short_description', 'description', 'friendly_url', 'main_menu', 'template_id');
        return $results;
    }

    public function getPrimaryKey() {
        $pk = $this->_primary;
        if (is_array($pk)) {
            if (count($pk) > 0)
            return $pk[1]; // array[1] contain column name of primary key
        }
        return $this->_primary;
    }

    function getMenuRecords($order = 'node.left') {

        $table_name = $this->_name;
        $primary_key = $this->_primary;
        if($primary_key)
        $primary_key = $primary_key[1];

        $select = Zend_Db_Table_Abstract::select();
        //        ->setIntegrityCheck(false)
        $select
        ->from(array('node' => $this->_name))
        ->join(array('parent'=> $this->_name), "node.left BETWEEN parent.left AND parent.right", array('depth' => 'COUNT(parent.left) -1'))
        ->group("node.$primary_key")
        ->order($order);

        echo $select;
        $data = $this->fetchAll($select);
        //$stmt = $select->query();
        //$data = $stmt->fetchAll();

        return $data;
    }
    
    public function url($obj) {
        $pk = $this->getPrimaryKey();
        return BASE_URL . "/index/shop/list/?cid=" . $obj[$pk];
    }
    
    public function getRecordsNormal($where = null, $order = null, $count = null, $offset = 0) {
        
        $data = array();
        
        $select = Zend_Db_Table_Abstract::select();
        $select->setIntegrityCheck(false);
        
        if($where) {
            $select->where($where);
        }
        if($order) {
            $select->order($order);
        }
        if($count)
            $select->limit($count, $offset);

        $stmt = $select->query();
        $data = $stmt->fetchAll();

        return $data;
    }
}
?>
